import threading
import time

# 获取线程的返回值

class MyThread(threading.Thread):

    def __init__(self, func, args=()):
        super(MyThread, self).__init__()
        self.func = func
        self.args = args
    
    def run(self):
        self.result = self.func(*self.args)

    def get_result(self):
        try:
            return self.result # 这里需要注意，如果线程没有使用join的方法则会报错
        except Exception as e:
            print(e)
            return None


def foo(a, b, c):
    time.sleep(1)
    return a * 2, b * 2, c * 2


st = time.time()
li = []
for i in range(4):
    t = MyThread(foo, (i, i + 1, i + 2))
    li.append(t)
    t.start()

for t in li:
    t.join() # 一定要加上join，不然主线程比子线程跑的快，就会出错
    print(t.get_result())

et= time.time()
print(et - st)